/*
package com.itheima.health.consumer;

import com.itheima.health.common.RedisConst;
import com.itheima.health.common.RocketMqConst;
import com.itheima.health.message.SmsTask;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.security.SecureRandom;
import java.util.concurrent.TimeUnit;

@Slf4j
@Component
@RocketMQMessageListener(topic = RocketMqConst.TOPIC_SMS_SEND, consumerGroup = "sms-send-consumer")
public  class SmsSendConsumer implements RocketMQListener<SmsTask> {

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    public void onMessage(SmsTask smsTask) {
        log.info("[短信发送消费者]received message: {}", smsTask);
        log.info("[短信发送消费者]模拟发送，发送中……");

        //生成随机四位数字验证码
        int code = (int) (new SecureRandom().nextDouble() * 8999 + 1000);
        //打印验证码到控制台,模拟发送短信
        log.info("[短信-验证码] code:{}",code);
        //保存验证码到redis中
        redisTemplate.boundValueOps(RedisConst.VALIDATE_CODE_PRE+smsTask.getContent()+"_"+smsTask.getPhone()).set(String.valueOf(code),30, TimeUnit.SECONDS);

        log.info("[短信发送消费者]发送成功");
    }

}
*/
